package test;

import test.Projectile.AmmoType;
import test.Weapon.WeaponType;
import util.VectorMath;
import movement.BasicPlayerMovement;
import movement.MoveModel;
import movement.WallBounce;
import jgame.JGColor;
import jgame.JGObject;

public class Player extends AbstractShooter {

	private int hitCount = 0;
	
	private static final int 	RADIUS		= 8;
	private static final String PLAYER_GFX 	= "player_l";
	private final MoveModel movement = new BasicPlayerMovement(2, .2);
	private final MoveModel wallMovement = WallBounce.getInstance();
	private Weapon weapon;
	

	public Player(String name, boolean uniqueId, double x, double y ) 
    {
		super(name, uniqueId, x, y, Collision.PLAYER, PLAYER_GFX);
		weapon = new BasicGun(AmmoType.PAINT_AMMO);
		
	}
	
	public void setWeapon(WeaponType type){
		weapon = WeaponFactory.get(type); 
	}
	
	public void fire(){
		weapon.fire(this);
	}
	
	@Override
	public void hit(JGObject obj){
		if (obj.colid == Collision.ENEMY){
			System.out.println("PLAYER REGISTERED ENEMY HIT");
			hitCount++;
		}
	}
	
	public int getEnemyHitCount(){
		return hitCount;
	}
	
	@Override
	public void move() {
		movement.move(this);
		wallMovement.move(this);
		
		//if (xspeed < 0) setGraphic("player_l"); else setGraphic("player_r");
		//if (yspeed < 0) setGraphic("player_u"); else setGraphic("player_d");
	}
    
	@Override
    public void paint(){
		super.paint();

		// not needed due to animation:
		//eng.setColor(JGColor.white);
        //eng.drawOval(x,y,RADIUS,RADIUS,true,true);
        
        
        // Draw aiming dot:
        // We get the direction of the mouse relative to the player 
        // by subtracting vP (the player) from vM (the mouse)
        // and normalizing the resultant vector.
        double[] normal =  getAim();
        eng.setColor(JGColor.blue);
        
        // We multiply this unit vector by the radius of the player and a constant
        // for a nice round smooth thingamajig
        eng.drawOval(x + normal[0] * RADIUS * 4, y + normal[1] * RADIUS * 4 , 4, 4, true, true);
    
    }
	
	public double[] getAim(){
		return VectorMath.normalize(eng.getMouseX() - x,eng.getMouseY() - y); 
	}
}
